package cn.wolfcode.luowowo.service.impl;

import cn.wolfcode.luowowo.cache.key.RedisKey;
import cn.wolfcode.luowowo.cache.service.IVerifyCodeCacheService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.TimeoutUtils;

import java.util.concurrent.TimeUnit;
@Service
public class VerifyCodeCacheServiceImpl implements IVerifyCodeCacheService {
    @Autowired
    private StringRedisTemplate template;
    @Override
    public void setVerifyCode(String phone,String verifyCode) {
        //获取key
        String key = RedisKey.VERIFY_CODE.getCacheKey(phone);
        //缓存验证码
        template.opsForValue().set(key,verifyCode,RedisKey.VERIFY_CODE.getTimeout(), TimeUnit.MILLISECONDS);
    }

    @Override
    public String getVerifyCode(String phone) {
        //获取key
        String key = RedisKey.VERIFY_CODE.getCacheKey(phone);
        String verifyCode = template.opsForValue().get(key);
        return verifyCode;
    }
}
